package formatter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import optimizer.DependencyTable;

public class AssemblyFileWriter {
	String filename;
	BufferedWriter writer;

	public AssemblyFileWriter(String fileNameWithPath){
		this.filename = fileNameWithPath;
		try {
			this.writer = new BufferedWriter(new FileWriter(new File(this.filename)));
		} catch (IOException e) {
			System.out.println("AssemblyFileWriter.AssemblyFileWriter() : Cannot write to file " + this.filename + " does not exists.");
		}
	}
	

	public void writeDependencyTable(DependencyTable t) throws IOException{
		this.writer.write(t.getTable());
	}
	
	public void writeProgram(DependencyTable t) throws IOException{	
		this.writer.write(t.getProgram());
	}

	public void closeFile(){
		if (writer != null)
			try {
				writer.close();
			} catch (IOException e) {
				System.out.println("AssemblyFileWriter.closeFile(): Error while closing the file - " + this.filename);
			}
	}
}
